﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.ThrongIn.BE ;
using System.Data ;
using System.Data.Common ;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Com.ThrongIn.DAL
{
    public class UserDAL
    {

        public User GetUser(string email, string password)
        {
          
            DbParameter[] param = new DbParameter[2];
            param[0] = DBInstance.ParameterInstance(DbType.String, "@in_email", email,ParameterDirection.Input);
            param[1] = DBInstance.ParameterInstance(DbType.String, "@in_password", password, ParameterDirection.Input);
            using (IDataReader reader = DBInstance.GetReader(StoredProc.GET_USER,param))
            {
                User user=null;
                if (reader.Read())
                {
                    user = new User();
                    DBInstance.PopulateEntity<User>(user, reader); 
                }
                return user;
            }
        }
            /// <summary>
       /// Add User
       /// </summary>
       /// <param name="fileComment"></param>
        public Int64 AddUser(User user)
        {
            DbParameter[] param = new DbParameter[3];
            param[0] = DBInstance.ParameterInstance(DbType.String, "in_first_name", user.First_Name, ParameterDirection.Input);
            param[1] = DBInstance.ParameterInstance(DbType.String, "in_last_name", user.Last_Name, ParameterDirection.Input);
            param[2] = DBInstance.ParameterInstance(DbType.String, "in_email", user.Email, ParameterDirection.Input);
            return Convert.ToInt64(DBInstance.ExecuteScalar(StoredProc.ADD_USER, param));           
        }

     }
}
